package com.system.web.spring;


import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//import com.workflow.WorkFlowUtils;
import com.common.db.JsonVO;
import com.common.db.Pg;
import com.common.utils.BeanUtils;
import com.system.domain.T_login_log;
import com.system.mapper.T_login_logMapper;
//import com.system.service.T_login_logMapperService;

//@Service
//@Transactional
@Controller
@RequestMapping("/t_login_log")

public class T_login_logController
{
	private static Logger log = Logger.getLogger(T_login_logController.class.getName());

	//@Autowired
    //private T_login_logService service;

	//@Autowired
	//private WorkFlowUtils workFlowUtils;

	@Resource
	private T_login_logMapper mapper;
	//private int id;
	//private int[] ids;
	private Pg pg;

	/**
	 * 1、获取 T_login_log信息列表，并且在列表页面展示
	 * @param request
	 * @return Pg，json格式
	 */
	@RequestMapping("/getAllT_login_log")
	@ResponseBody
	public Pg getAllT_login_log(HttpServletRequest request){
        int pageSize = 10;
        int startIndex = 0;
        T_login_log t_login_log = new T_login_log();
        try{
	        if(request.getParameter("pageSize")!=null){
	        	pageSize = BeanUtils.stringToInt("pageSizeFlag", request.getParameter("pageSize"));
	        }
	        if(request.getParameter("startIndex")!=null){
	            startIndex = BeanUtils.stringToInt("startIndexFlag", request.getParameter("startIndex"));
	        }
	        if(request.getParameter("process_code")!=null){ //取得动作流 流程英文名称，后台查询数据关联使用
	        	t_login_log.setProcess_code(request.getParameter("process_code"));
	        }
			if(request.getParameter("userid")!=null&&!"".equals(request.getParameter("userid"))){
	        	t_login_log.setUserid(request.getParameter("userid"));
	        }
			if(request.getParameter("login_in_tm")!=null&&!"".equals(request.getParameter("login_in_tm"))){
	        	t_login_log.setLogin_in_tm(request.getParameter("login_in_tm"));
	        }
			if(request.getParameter("login_out_tm")!=null&&!"".equals(request.getParameter("login_out_tm"))){
	        	t_login_log.setLogin_out_tm(request.getParameter("login_out_tm"));
	        }
			if(request.getParameter("login_fail_tm")!=null&&!"".equals(request.getParameter("login_fail_tm"))){
	        	t_login_log.setLogin_fail_tm(request.getParameter("login_fail_tm"));
	        }
			if(request.getParameter("login_addr")!=null&&!"".equals(request.getParameter("login_addr"))){
	        	t_login_log.setLogin_addr(request.getParameter("login_addr"));
	        }
			if(request.getParameter("login_remark")!=null&&!"".equals(request.getParameter("login_remark"))){
	        	t_login_log.setLogin_remark(request.getParameter("login_remark"));
	        }
			if(request.getParameter("session_id")!=null&&!"".equals(request.getParameter("session_id"))){
	        	t_login_log.setSession_id(request.getParameter("session_id"));
	        }
			if(request.getParameter("crt_tm")!=null&&!"".equals(request.getParameter("crt_tm"))){
	        	t_login_log.setCrt_tm(request.getParameter("crt_tm"));
	        }
      	    if(request.getParameter("log_id")!=null&&!"".equals(request.getParameter("log_id"))){
	        	t_login_log.setLog_id(new Integer(request.getParameter("log_id")));
	        }

	        if(request.getParameter("startdate")!=null&&!"".equals(request.getParameter("startdate"))){
	        	t_login_log.setStartdate(request.getParameter("startdate"));
	        }
	        if(request.getParameter("enddate")!=null&&!"".equals(request.getParameter("enddate"))){
	        	t_login_log.setEnddate(request.getParameter("enddate"));
	        }
	        t_login_log.setStartNo( startIndex );
	        t_login_log.setEndNo( startIndex + pageSize );
	    	List<T_login_log> findAll = mapper.findAll(t_login_log);
	        int totalCount = mapper.findCountAll(t_login_log);
	       	pg = new Pg(findAll, totalCount, pageSize, startIndex);
	       	request.setAttribute("t_login_logList", findAll);
		    request.setAttribute("pg", pg);
	    } catch (Exception e) {
			e.printStackTrace();
			log.error("------query t_login_logList error:"+e);
		}

		return pg;
	}

	/**
	 * 2、新增保存  T_login_log信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param user
	 * @param request
	 * @return
	 */
	@RequestMapping("/saveT_login_log")
	@ResponseBody
	public JsonVO saveT_login_log(T_login_log t_login_log, HttpServletRequest request,HttpServletResponse response){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊需求，需要将json对象值转成java实体对象属性值
		if(mapper.save(t_login_log)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 3、修改T_login_log信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_login_log
	 * @param request
	 * @return JsonVO
	 */
	@RequestMapping("/updateT_login_log")
	@ResponseBody
	public JsonVO updateT_login_log(T_login_log t_login_log, HttpServletRequest request){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊值需要处理，在此处手工转换
		//T_login_log t_login_logTemp = mapper.findById(t_login_log);
		//t_login_logTemp.setXXX(t_login_log.getXXX());
		//if(mapper.update(t_login_logTemp)){

		if(mapper.update(t_login_log)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 4、根据id查询T_login_log单个信息并显示在修改页面
	 * @param id
	 * @param request
	 * @return T_login_log json格式字符串
	 */
	@RequestMapping("/getT_login_log")
	@ResponseBody
	public T_login_log getT_login_log(Integer id,HttpServletRequest request){
		T_login_log t_login_log = new T_login_log();
		t_login_log.setLog_id(id);
		return mapper.findById(t_login_log);
	}

	/**
	 * 5、删除T_login_log根据id
	 * @param id
	 * @param request
	 * @param response
	 * return JsonVO ：json格式字符串
	 */
	@RequestMapping("/delT_login_log")
	@ResponseBody
	public JsonVO delT_login_log(Integer id,HttpServletRequest request,HttpServletResponse response){
        JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);

		T_login_log t_login_log = new T_login_log();
		t_login_log.setLog_id(id);

		if(mapper.delete(t_login_log)>0){
			vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 6、跳转到t_login_log/toT_login_logList查询所有数据页面
	 *  return /WEB-INF/views/system/t_login_log/t_login_logList.jsp
	 */
    @RequestMapping(value = "/toT_login_logList")
    public String toT_login_logList() {
    	log.debug("------跳转到/WEB-INF/views/system/t_login_log/t_login_logList.jsp------");
        return "system/t_login_log/t_login_logList";
    }

	/**
	 * 7、新增、修改、详情页面t_login_log/toT_login_logCurd跳转
     * system/t_login_log/T_login_logCurd.jsp
	 */
    @RequestMapping(value = "/toT_login_logCurd")
    public String toT_login_logCurd() {
    	log.debug("------跳转到/WEB-INF/views/system/t_login_log/t_login_logCurd.jsp------");
        return "system/t_login_log/t_login_logCurd";
    }

    /**
	 * 8、批量删除T_login_log根据主键id
	 * 是否要实现批量删除，待考虑，基本上用途不大
	 * @param id
	 * @param request
	 * @param response
	@RequestMapping("/delT_login_logBatch")
	public String delT_login_logBatch(HttpServletRequest request,HttpServletResponse response){
		String[] ids = request.getParameterValues("ids");
		System.out.println("------ids="+ids);
		T_login_log t_login_log = new T_login_log();
		int j=0;
		for(int i =0;i< ids.length;i++){
			j++;
			log.error("------ids[i]="+ids[i]);
			t_login_log.setLog_id(new Integer(ids[i]).intValue());
			mapper.delete(t_login_log);
		}
		if(j==ids.length){
			log.debug("------t_login_log批量删除成功！------");
		}else{
			log.error("------t_login_log批量删除部分成功！部分失败！------");
		}

		return "redirect:/t_login_log/getAllT_login_log";
	}
*/



}









